import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:旋转数组
 * User: dings
 * Date: 2024-06-01
 * Time: 10:18
 */
class Solution {
    //456789
    public void rotate(int[] nums, int k) {
        int len = nums.length;
        k %= len;
        int forIndex = nums.length - k;
        int tmp = forIndex;
        int[] arr1 = new int[len];
        for (int i = 0; i < k; i++) {
            arr1[i] = nums[tmp];
            tmp++;
        }
        int j = 0;
        for (int i = k; i < len; i++) {
            arr1[i] = nums[j];
            j++;
        }
        for (int i = 0; i < len; i++) {
            nums[i] = arr1[i];
        }
    }
}
/*class Solution {
    //123456789
    public void rotate(int[] nums, int k) {
        int len = nums.length;
        int len2 = len - k;
        int[] arr = new int[len];
        char[] arr1 = new char[len];
        for (int i = 0; i < len; i++) {
            arr1[i] = (char) (nums[i] + '0');
        }
        String tmp = String.valueOf(arr1);
        String part1 = tmp.substring(len2);
        int tmpLen = part1.length();
        for (int i = 0; i < tmpLen; i++) {
            arr[i] = part1.charAt(i) - '0';
        }
        for (int i = 0; i < len2; i++) {
            arr[i + k] = tmp.charAt(i) - '0';
        }
        System.out.println(Arrays.toString(arr));
    }
}*/
    //2 3    4
/*class Solution {
    //123456789
    public void rotate(int[] nums, int k) {
        int len = nums.length;
        int tmp = 0;
        for (int j = 0; j < k; j++) {
            tmp = nums[len - 1];
            for (int i = len - 2; i >= 0; i--) {
                nums[i + 1] = nums[i];
            }
            nums[0] = tmp;
        }
        System.out.println(Arrays.toString(nums));
    }
}*/
public class Test {
    public static void main(String[] args) {
        int[] nums = {1,2};
        Solution solution = new Solution();
        solution.rotate(nums,3);
        System.out.println(Arrays.toString(nums));
    }
}
